package com.vision.frame.swagger;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 前后端交互 API配置
 * 只有ts.swagger-enable设置成true的时候启用
 * @author xhc
 */
@Configuration
@EnableSwagger2
@ConditionalOnProperty(name = "vision.swagger-enable",havingValue = "true")
public class Swagger2 {

    @Bean
    public Docket createApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("活动流程")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.vision.pdp.Activity"))
                .paths(PathSelectors.any())
                .build();
    }


    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("PMLite构建api文档")
                .contact(new Contact("visionmc","https://visionmc.vicp.net",""))
                .description("客户端和服务器接口文档")
                .termsOfServiceUrl("http://localhost:8080/PML")
                .version("1.0")
                .build();

    }
}
